package com.xiaohai.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaohai.common.R;
import com.xiaohai.projo.Class;
import com.xiaohai.projo.dto.MajorDto;
import com.xiaohai.projo.dto.StudentDto;
import com.xiaohai.service.ClassService;
import com.xiaohai.service.MajorService;
import com.xiaohai.service.ScoreService;
import com.xiaohai.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * ClassName:EchartsController
 * Package:IntelliJ IDEA
 * Description:
 * Author 何诗海
 *
 * @Create 2024/3/1 9:17
 * @Version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/echart")
public class EchartsController {
    @Autowired
    private ClassService classService;
    @Autowired
    private MajorService majorService;

    @Autowired
    private StudentService studentService;

    @Autowired
    private ScoreService scoreService;

    @GetMapping("/class")
    public R<Object> aclass() {
        Map<String, Integer> map = new HashMap<>();
        List<Class> list = classService.list();
        list.forEach(a -> {
            Integer total = a.getTotal();
            String name = a.getName();
            map.put(name, total);
        });
        return R.success(map, "获取数据成功");
    }

    @GetMapping("/majorPerson")
    public R<List<MajorDto>> majorPerson() {
        List<MajorDto> majorPerson = majorService.majorPerson();
        return R.success(majorPerson, "获取数据成功");
    }

    @GetMapping("/menWomen")
    public R<List<HashMap<String, Integer>>> menWomen() {
        List<HashMap<String, Integer>> maps = studentService.getMenWomen();
        return R.success(maps, "获取数据成功");
    }

    @GetMapping("/grade")
    public R<Object> grade(Integer identity,String name,String account) {
        List<HashMap<String, Integer>> maps = studentService.list1(identity,name,account);
        return R.success(maps, "获取数据成功");
    }

    @GetMapping("/name")
    public R<Object> grade() {
        List<String> maps = scoreService.getNameList();
        return R.success(maps, "获取数据成功");
    }
}
